<!DOCTYPE html>
<html>
  <head>
    <meta charSet="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
    <title>{$info.project_name}项目群智能系统设计选型结果</title>
    <style type="text/css">
    .container {margin:5px;padding:0 20px;text-align:center;}
    table{
      border-collapse: collapse;
      border: 1px solid #000;
      width:100%;
    }

    table th {
      border: 1px solid #000;
      padding:4px 5px;
      line-height:1.2;
      font-size:12px;
      letter-spacing:1px;
    }
    
    table td {
      border: 1px solid #000;
      padding:4px 5px;
      line-height:1.2;
      font-size:12px;
      text-align:center;
    }

    table.title{border:0px;}
    table.title td{border:0px;}

    table.noborder td{
      border:0px;
    }
    </style>
  </head>
  <body>
    <div class="container">
      <h2 class="text-center">{$info.project_name}项目群智能系统设计选型结果</h2>
      <php>
        $control_colspan = count($headers['controls']);
        $sensor_colspan = count($headers['sensors']);
        $sign_colspan = count($headers['signs']);
        $total_colspan = $control_colspan + $sensor_colspan + $sign_colspan + 6;
      </php>
      <table class="table table-bordered table-hover mb-5" border="1">
        <thead>
          <tr>
            <th rowspan="2">序号</th>
            <th rowspan="2">CPN编号</th>
            <th rowspan="2">专用控制器类型</th>
            <th rowspan="2">被控设备编号或数量</th>
            <th rowspan="2">安装楼层</th>
            <th rowspan="2">备注</th>
            <th colspan="{$control_colspan}">控制模块选型结果</th>
            <th colspan="{$sensor_colspan}">传感器、执行器等选型结果</th>
            <th colspan="{$sign_colspan}">监控点位数量</th>
          </tr>
          <tr>
            <volist name="headers.controls" id="h">
              <th>{$h}</th>
            </volist>
            <volist name="headers.sensors" id="h">
              <th>{$h}</th>
            </volist>
            <volist name="headers.signs" id="h">
              <th>{$h}</th>
            </volist>
          </tr>
        </thead>
        <tbody>
          <php>
            $control_arr = $sensor_arr = $sign_arr = array();
            foreach($data as $cpn=>$v){
              //控制器，传感器，信号总数
              foreach($v['controls'] as $k=>$vv){
                $control_arr[$k][] = $vv;
              }

              foreach($v['sensors'] as $k=>$vv){
                $sensor_arr[$k][] = $vv['count'];
              }

              foreach($v['signs'] as $k=>$vv){
                $sign_arr[$k][] = $vv;
              }
             
              //获取传感器参数
              foreach($v['sensors'] as $k=>$vv){
                  $param_arr[$k] = $vv['param_str'];
              }
          }

          </php>
          <volist name="data" id="vo">
          <tr>
            <td>{$i}</td>
            <td>{$vo.cpn_sn}</td>
            <td>{$vo.group_name}</td>
            <td>{$vo.device_sn}</td>
            <td>{$vo.floor_name}</td>
            <td>{$vo.intro}</td>
            <php>
              foreach($headers['controls'] as $h){
                $zhi = empty($vo['controls'][$h]) ? 0 : $vo['controls'][$h];
                echo '<td>'.$zhi.'</td>';
              }

              foreach($headers['sensors'] as $h){
                $zhi = empty($vo['sensors'][$h]) ? 0 : $vo['sensors'][$h];
                echo '<td>'.$zhi.'</td>';
              }

              foreach($headers['signs'] as $h){
                $zhi = empty($vo['signs'][$h]) ? 0 : $vo['signs'][$h];
                echo '<td>'.$zhi.'</td>';
              }
            </php>
          </tr>
          </volist>
          <tr style="background:#90EE90;">
            <td colspan="6">总计</td>
            <php>
              foreach($headers['controls'] as $h){
                $zhi = array_sum($control_arr[$h]) ?: 0;
                echo '<td>'.$zhi.'</td>';
              }

              foreach($headers['sensors'] as $h){
                $zhi = array_sum($sensor_arr[$h]) ?: 0;
                echo '<td>'.$zhi.'</td>';
              }

              foreach($headers['signs'] as $h){
                $zhi = array_sum($sign_arr[$h]) ?: 0;
                echo '<td>'.$zhi.'</td>';
              }
            </php>
          </tr>
          <tr>
            <td colspan="{$total_colspan}" style="text-align: left;">
              <p><strong>传感器、执行器等选型参数要求说明：</strong></p>
              <php>
                $content = '';
                foreach($headers['sensors'] as $k=>$v){
                    $content .= '<p>' . $v . "：" . str_replace("#", "    ", $param_arr[$k]) . '</p>';
                }
              </php>
              <P>
                {$content}
              </P>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <!-- div style="page-break-after:always"></div -->
    <php>
    foreach($monitor_columns as $group=>$v):
      if(empty($monitor_data[$group])) continue;
    </php>
    <pagebreak></pagebreak>
    <div class="container">
      <div style="margin-top:30px;"></div>
      <h2 class="text-center">{$group}专用控制器监控点表</h2>
      <table class="table table-bordered table-hover mb-5" border="1">
        <thead>
          <tr>
            <th>序号</th>
            <th>CPN编号</th>
            <th>专用控制器类型</th>
            <php>
              foreach($v as $vv){
                echo '<th>'.$vv.'</th>';
              }
            </php>
          </tr>
          </thead>
          <tbody>
            <volist name="monitor_data[$group]" id="vo">
              <tr>
                <td>{$i}</td>
                <td>{$vo.name}</td>
                <td>{$vo.controls}</td>
                <php>
                  foreach($monitor_columns[$group] as $param_name){
                    if(in_array($param_name, $vo['param_names'])){
                      echo '<td>●</td>';
                    } else {
                      echo '<td>&nbsp;</td>';
                    }
                  }
                </php>
              </tr>
            </volist>
          </tbody>
          </table>
        </div>
      <php>endforeach;</php>
  </body>
</html>